package it.koutifaris.travianmap.view.serversview;

import it.koutifaris.travianmap.R;
import it.koutifaris.travianmap.context.HasApplicationContex;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class ServersViewImpl extends HasApplicationContex implements ServersView {

	public ServersViewImpl() {
	}

	@Override
	public ListView getListView() {
		return (ListView) getActivity().findViewById(R.id.serversListView);
	}

	@Override
	public void setAddServerMenuItemClickHandler(Menu menu, OnMenuItemClickListener clickListener) {
		MenuItem menuItem = menu.findItem(R.id.addServer);
		menuItem.setOnMenuItemClickListener(clickListener);
	}

	@Override
	public ServersViewItem newViewItem(ViewGroup parent, View convertView) {
		View result = convertView;

		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			result = inflater.inflate(R.layout.servers_list_item, parent, false);
		}

		return new ServersViewItemImpl(result);
	}
}
